'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Public Class IcqStatusCodes
    Private Shared ReadOnly _Online As IcqStatusCode = New IcqStatusCode("Online", IcqInterface.DataTypes.UserStatus.Online, 0)
    Private Shared ReadOnly _Free4Chat As IcqStatusCode = New IcqStatusCode("Free4Chat", IcqInterface.DataTypes.UserStatus.FreeForChat, 1)
    Private Shared ReadOnly _Invisible As IcqStatusCode = New IcqStatusCode("Invisible", IcqInterface.DataTypes.UserStatus.Invisible, 2)
    Private Shared ReadOnly _Away As IcqStatusCode = New IcqStatusCode("Away", IcqInterface.DataTypes.UserStatus.Away, 3)
    Private Shared ReadOnly _DoNotDisturb As IcqStatusCode = New IcqStatusCode("Do not disturb", IcqInterface.DataTypes.UserStatus.DoNotDisturb, 4)
    Private Shared ReadOnly _Occupied As IcqStatusCode = New IcqStatusCode("Occupied", IcqInterface.DataTypes.UserStatus.Occupied, 5)
    Private Shared ReadOnly _NotAvailable As IcqStatusCode = New IcqStatusCode("Not Available", IcqInterface.DataTypes.UserStatus.NotAvailable, 6)
    Private Shared ReadOnly _Offline As IcqStatusCode = New IcqStatusCode("Offline", IcqInterface.DataTypes.UserStatus.Offline, 7)
    Private Shared ReadOnly _Unknown As IcqStatusCode = New IcqStatusCode("Unknown status", IcqInterface.DataTypes.UserStatus.Offline, 8)

    Public Shared ReadOnly Property Online() As IcqStatusCode
        Get
            Return _Online
        End Get
    End Property

    Public Shared ReadOnly Property Offline() As IcqStatusCode
        Get
            Return _Offline
        End Get
    End Property

    Public Shared ReadOnly Property Occupied() As IcqStatusCode
        Get
            Return _Occupied
        End Get
    End Property

    Public Shared ReadOnly Property NotAvailable() As IcqStatusCode
        Get
            Return _NotAvailable
        End Get
    End Property

    Public Shared ReadOnly Property Invisible() As IcqStatusCode
        Get
            Return _Invisible
        End Get
    End Property

    Public Shared ReadOnly Property Free4Chat() As IcqStatusCode
        Get
            Return _Free4Chat
        End Get
    End Property

    Public Shared ReadOnly Property Away() As IcqStatusCode
        Get
            Return _Away
        End Get
    End Property

    Public Shared ReadOnly Property DoNotDisturb() As IcqStatusCode
        Get
            Return _DoNotDisturb
        End Get
    End Property

    Public Shared Function GetStatusCode(ByVal status As IcqInterface.DataTypes.UserStatus) As IcqStatusCode
        Select Case status
            Case DataTypes.UserStatus.Away
                Return _Away
            Case DataTypes.UserStatus.DoNotDisturb
                Return _DoNotDisturb
            Case DataTypes.UserStatus.FreeForChat
                Return _Free4Chat
            Case DataTypes.UserStatus.Invisible
                Return _Invisible
            Case DataTypes.UserStatus.NotAvailable
                Return _NotAvailable
            Case DataTypes.UserStatus.Occupied
                Return _Occupied
            Case DataTypes.UserStatus.Offline
                Return _Offline
            Case DataTypes.UserStatus.Online
                Return _Online
            Case Else
                Return _Unknown
        End Select
    End Function
End Class

Public Class IcqStatusCode
    Implements Interfaces.IStatusCode

    Private _Attributes As Hashtable = New Hashtable
    Private _DisplayName As String
    Private sortIndex As Integer

    Public Sub New(ByVal name As String, ByVal icqStatus As DataTypes.UserStatus, ByVal sort As Integer)
        _DisplayName = name
        _Attributes("IcqUserStatus") = icqStatus
        sortIndex = sort
    End Sub

    Public ReadOnly Property Attributes() As System.Collections.Hashtable Implements Interfaces.IStatusCode.Attributes
        Get
            Return _Attributes
        End Get
    End Property

    Public ReadOnly Property DisplayName() As String Implements Interfaces.IStatusCode.DisplayName
        Get
            Return _DisplayName
        End Get
    End Property

    Public ReadOnly Property IcqUserStatus() As DataTypes.UserStatus
        Get
            Return DirectCast(_Attributes("IcqUserStatus"), DataTypes.UserStatus)
        End Get
    End Property

    Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
        Dim x As IcqStatusCode = TryCast(obj, IcqStatusCode)

        If x IsNot Nothing Then Return Comparer.Default.Compare(sortIndex, x.sortIndex)
    End Function

    Public Overrides Function ToString() As String
        Return DisplayName
    End Function
End Class
